<?php
/**
 * This FuneralHome class contains methods to work with the FuneralHome database table
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 * @link       http://my-trac.assembla.com/amemorytree/ticket/??
 */
class FuneralHomeDB
{
    /**
     * Reference to the database
     * 
     * @var Db
     */
    private $_db;
    /**
     * Create a new instance of the database access methods for funeral homes
     * 
     * @param Db &$db
     */
    public function __construct(&$db)
    {
        $this->_db = $db;
    }
    /**
     * Count the number of duplicate funeral home names
     *
     * @return int
     * @param mixed $funeralName
     * @param mixed $funeralId
     */
    public function countDuplicateFuneralNames($funeralName, $funeralId)
    {
        $funeralId = $this->_db->put($funeralId);
        $funeralName = $this->_db->put($funeralName);
        $sql = "SELECT COUNT(*) FROM FuneralHome WHERE Name = '$funeralName' AND NOT ID = '$funeralId'";
        $result = $this->_db->query($sql);
        $row = $this->_db->fetchRow($result);
        return intval($this->_db->get($row[0]));
    }
    /**
     * Get funeral home name
     *
     * @return string
     * @param mixed $funeralHomeId
     */
    function getName($funeralHomeId)
    {
        global $db;
        $funeralHomeId = $db->put($funeralHomeId);
        $sql = "SELECT Name FROM FuneralHome WHERE ID = $funeralHomeId";
        $result = $db->query($sql);
        $row = $db->fetch($result);
        $funeralHomeName = $db->get($row['Name']);
        return $funeralHomeName;
    }
    /**
     * Set the name of a funeral home
     *
     * @return bool
     * @param mixed $funeralName
     * @param mixed $funeralId
     */
    function setName($funeralName, $funeralId)
    {
        $funeralName = $this->_db->put($funeralName);
        $funeralId = $this->_db->put($funeralId);
        $sql = "UPDATE FuneralHome SET Name = '$funeralName' WHERE ID = $funeralId";
        return $this->_db->query($sql) === TRUE;
    }
}
?>

